home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / mpload / mpload.lzh / MPLOAD.C < prev    next >
Text File  |  1991-01-28  |  4KB  |  221 lines

  1. /*
  2.  *        Mac Paint file Loader
  3.  *                                        (C) 1989-1991 Waku Factory
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <egb.h>
  8. #include <mos.h>
  9. #include <snd.h>
  10. #include <msdos.cf>
  11. #include "crtc.h"
  12.  
  13. #define PIXWIDTH 576
  14. #define PIXHEIGHT 720
  15. #define PIXDWORD (PIXWIDTH/8)
  16. #define VHO 16
  17.  
  18. static char name[] = "Mac-Paint Loader V1.0   (C) 1989-1991 Waku Factory" ;
  19.  
  20. char lbuf[ PIXDWORD ] ;
  21.  
  22. char work[1536] ;
  23. char mwork[4096] ;
  24. unsigned long pixbuf[PIXDWORD*PIXHEIGHT] ;
  25. int headsize ;
  26.  
  27. long table[256] ;
  28. void mktable()
  29. {
  30.     int i,j,b ;
  31.     unsigned long p ;
  32.     for( i = 0 ; i < 256 ; i++ ) {
  33.         p = 0 ;
  34.         b = i ;
  35.         for( j = 0 ; ; j++ ) {
  36.             if( b & 1 ) p += 0xF ;
  37.             if( j == 7 ) break ;
  38.             b >>= 1 ;
  39.             p <<= 4 ;
  40.         }
  41.         table[i] = p ;
  42.     }
  43. }
  44.  
  45.  
  46. void setsmode( )
  47. {
  48.     EGB_init( work, 1536 ) ;
  49.     EGB_resolution( work, 0, 3 ) ;
  50.     EGB_displayPage( work, 1, 3 ) ;
  51.     MOS_start( mwork, 4096 ) ;
  52.     SND_elevol_init() ;         /* cd mute off */
  53.     SND_elevol_set( 1,127,127 ) ;
  54.     MOS_writePage( 1 ) ;
  55.     MOS_color( 0, 8 ) ;
  56.     MOS_vertical( 0, 479 ) ;
  57.     MOS_horizon( 0, 639 ) ;
  58.  
  59.     putstr( 40, 477, "Waku Factory" ) ;
  60.  
  61.     MOS_disp( 1 ) ;
  62. /*
  63.     CRTC( CA_LO0, LOFS/8 ) ;
  64.     CRTC( CA_HDE0, 714 ) ;
  65. */
  66. }
  67.  
  68. putstr( x,y, str )
  69. int x,y ;
  70. char *str ;
  71. {
  72.     struct {
  73.         short x,y,len ;
  74.         char s[80] ;
  75.     } p ;
  76.     
  77.     p.x = x ;
  78.     p.y = y ;
  79.     p.len = strlen( str ) ;
  80.     strcpy( p.s, str ) ;
  81.     EGB_sjisString( work, (char *)&p ) ;
  82. }
  83.  
  84.  
  85. int fl = 0 ;
  86. void rollup( l )
  87. int l ;
  88. {
  89.     if( (fl += l) > 511 ) fl -= 512 ;
  90.     CRTC( CA_FA0, (1024/8) * fl ) ;
  91. }
  92.  
  93. void rolldown( l )
  94. int l ;
  95. {
  96.     if( (fl -= l) < 0 ) fl += 512 ;
  97.     CRTC( CA_FA0, (1024/8) * fl ) ;
  98. }
  99.  
  100.  
  101. int getimage( sfp ) 
  102. FILE *sfp ;
  103. {
  104.     int l,x,cnt,ch ;
  105.          
  106.     fseek( sfp, headsize, SEEK_SET ) ;
  107.     
  108.     for( l = 0 ; l < PIXHEIGHT ; l++ ) {
  109.         x = cnt = 0 ;
  110.         while( (ch = getc( sfp )) != EOF ) {
  111.             ch &= 0xFF ;
  112.             if( cnt-- == 0 )
  113.                 if( ch < 72 ) {
  114.                     cnt = ch + 1 ;
  115.                 }
  116.                 else {
  117.                     cnt = 257 - ch ;
  118.                     ch = getc( sfp ) ^ 0xFF ;
  119.                     while( cnt-- > 0 ) {
  120.                         lbuf[x++] = ch ;
  121.                         if( x == 72 ) goto exit ;
  122.                     }
  123.                     cnt = 0 ;
  124.                 }
  125.             else {
  126.                 lbuf[x++] = ch ^ 0xFF ;
  127.                 if( x == 72 ) goto exit ;
  128.             }
  129.         }
  130.     exit:    
  131.         putlbuf( l ) ;
  132.     }
  133. }
  134.  
  135. putlbuf( l )
  136. int l ;
  137. {
  138.     short w[8] ;
  139.     int i,ofs ;
  140.  
  141.     ofs = l * PIXDWORD ;
  142.     for( i = 0 ; i < PIXDWORD ; i++ ) {
  143.         pixbuf[ofs+i] = table[ lbuf[i] ] ;
  144.     }
  145. }
  146.  
  147. int scroll()
  148. {
  149.     unsigned long *p ;
  150.     int ofs, b, x, y ;
  151.     int uofs,dofs ;
  152.     
  153.     p = pixbuf ;
  154.     ofs = 0 ;
  155.     for( y = 0 ; y < 480 ; y++ ) {
  156.         for( x = 0 ; x < PIXDWORD ; x++,p++ ){
  157.             putVRAMd( ofs+VHO, *p, 0x104 ) ;
  158.             ofs += 4 ;
  159.         }
  160.         ofs += (1024 - PIXWIDTH)/2 ;
  161.     }
  162.     uofs = 0 ;
  163.     dofs = 479 ;
  164.     for(;;) {
  165.         MOS_rdpos( &b,&x,&y ) ;
  166.         if( b != 0 ) break ;
  167.         if( (y == 0) && (uofs != 0) ) {
  168.             rolldown( 1 ) ;
  169.             --dofs ;
  170.             p = &pixbuf[(--uofs) * PIXDWORD] ;
  171.             b = fl * 1024/2 ;
  172.             for( ofs = b ; ofs < b + PIXWIDTH/2 ; ofs+=4 )
  173.                 putVRAMd( ofs+VHO, *p++ , 0x104 ) ;
  174.         } else if( (y == 479) && (dofs != (PIXHEIGHT-1))) {
  175.             rollup( 1 ) ;
  176.             ++uofs ;
  177.             p = &pixbuf[(++dofs) * PIXDWORD] ;
  178.             b = ((fl + 479)*1024/2) & 0x3FFFF ;
  179.             for( ofs=b ; ofs < b + PIXWIDTH/2 ; ofs+=4 )
  180.                 putVRAMd( ofs+VHO, *p++, 0x104 ) ;
  181.         }
  182.     }
  183.     while( uofs ) {
  184.         rolldown( 1 ) ;
  185.         p = &pixbuf[(--uofs) * PIXDWORD] ;
  186.         b = fl * 1024/2 ;
  187.         for( ofs = b ; ofs < b + PIXWIDTH/2 ; ofs+=4 )
  188.             putVRAMd( ofs+VHO, *p++ , 0x104 ) ;
  189.     }
  190.     return b ;
  191. }
  192.  
  193. void main(ac,av) 
  194. char **av ;
  195. int ac ;
  196. {
  197.     FILE *fp ;
  198.     int i,r ;
  199.     
  200.     mktable() ;
  201.     setsmode() ;
  202.  
  203.     r = 1 ;
  204.     headsize = 512 + 128 ;
  205.     if( *av[1] == '-' && *(av[1]+1) == 'r' ) {
  206.         headsize = 512 ;
  207.         r++ ;
  208.     }
  209.     i = r ;
  210.     for( ; ; ) {
  211.         if( (fp = fopen( av[i], "rb" )) == NULL )
  212.              continue ;
  213.         getimage( fp ) ;
  214.         fclose( fp ) ;
  215.         if( scroll() == 2 ) break ;
  216.         if( ac == r+1 ) break ; 
  217.         if( ++i == ac ) i = r ;
  218.     }
  219.     MOS_end() ;
  220. }
  221.